using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml;
using MEA.AE_Data;
using MEA.AE_Data.Config;
using MEA.Chart;
using Microsoft.Win32;

namespace MEA.AE_BusinessLogic
{
	public class Xml_Log
	{
		public class CXmlFileLogInfo
		{
			public string filename;

			public string fileCreation;

			public string swName;

			public string swVer;

			public string ecuSWVer;

			public string engineTypeA;

			public string engineTypeB;

			public string engineSerNrA;

			public string engineSerNrB;

			public string engineTimeA;

			public string engineTimeB;

			public string ecuType;

			public string ecuSerialNrA;

			public string ecuSerialNrB;

			public string ecuHWRevisionA;

			public string ecuHWRevisionB;

			public string ecuSWRevisionA;

			public string ecuSWRevisionB;

			public string ecuTotalTimeA;

			public string ecuTotalTimeB;

			public string ecuTotalActTimeA;

			public string ecuTotalActTimeB;

			public string ecuRTCA;

			public string ecuRTCB;

			public List<string> ecuSectorWarnList;

			public List<string> ecuLiLoWarnList;

			public List<string> ecuEvRecWarnList;

			public List<string> powerLewerWarnList;

			public void AddWarnToSectorInfo(string wrn)
			{
				if (wrn != null && wrn != string.Empty)
				{
					if (ecuSectorWarnList == null)
					{
						ecuSectorWarnList = new List<string>();
					}
					ecuSectorWarnList.Add(wrn);
				}
			}

			public void AddWarnToLiLoInfo(string wrn)
			{
				if (wrn != null && wrn != string.Empty)
				{
					if (ecuLiLoWarnList == null)
					{
						ecuLiLoWarnList = new List<string>();
					}
					ecuLiLoWarnList.Add(wrn);
				}
			}

			public void AddEvRecWarnInfo(string wrn)
			{
				if (wrn != null && wrn != string.Empty)
				{
					if (ecuEvRecWarnList == null)
					{
						ecuEvRecWarnList = new List<string>();
					}
					ecuEvRecWarnList.Add(wrn);
				}
			}

			public void AddPowerLevelWarning(string wrn)
			{
				if (wrn != null && wrn != string.Empty)
				{
					if (powerLewerWarnList == null)
					{
						powerLewerWarnList = new List<string>();
					}
					powerLewerWarnList.Add(wrn);
				}
			}
		}

		private XmlWriter writer;

		private string shortlogpath;

		private string logpath;

		public MemoryStream myStream;

		public XmlWriter Writer
		{
			get
			{
				return writer;
			}
		}

		public event EventHandler<ServiceLayerStringEventArg> ev_ProgressStep;

		public event EventHandler<ServiceLayerBoolEventArg> ev_ProgressClose;

		public ConfigData.e_FileTypes ReadFiletype(Stream mstream)
		{
			XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
			XmlReader xmlReader;
			try
			{
				mstream.Position = 0L;
				xmlReaderSettings.ProhibitDtd = false;
				xmlReader = XmlReader.Create(mstream, xmlReaderSettings);
			}
			catch
			{
				return ConfigData.e_FileTypes.INVALID;
			}
			try
			{
				ConfigData.e_FileTypes e_FileTypes = ConfigData.e_FileTypes.INVALID;
				while (xmlReader.Read() && e_FileTypes == ConfigData.e_FileTypes.INVALID)
				{
					switch (xmlReader.Name)
					{
					case "ENGINE_LOG":
						e_FileTypes = ConfigData.e_FileTypes.ENGINE_LOG;
						break;
					case "EVENTREC_FILE":
						e_FileTypes = ConfigData.e_FileTypes.EVENT_REC;
						break;
					case "FLASH_CONTAINER":
						e_FileTypes = ConfigData.e_FileTypes.FLASH_CONTAINER;
						break;
					case "RECMAN_HEXDUMP_EVREC":
						e_FileTypes = ConfigData.e_FileTypes.EVENT_REC;
						break;
					case "RECMAN_HEXDUMP_EVREC_ONLY":
						e_FileTypes = ConfigData.e_FileTypes.EVENT_REC;
						break;
					case "RECMAN_HEXDUMP_DATLOG":
						e_FileTypes = ConfigData.e_FileTypes.DAT_LOG;
						break;
					case "RECMAN_HEXDUMP_DATLOG_ONLY":
						e_FileTypes = ConfigData.e_FileTypes.DAT_LOG;
						break;
					case "IQA_FILE":
						e_FileTypes = ConfigData.e_FileTypes.IQA;
						break;
					case "IQA_STORAGE_FILE":
						e_FileTypes = ConfigData.e_FileTypes.IQA_STORAGE;
						break;
					case "LIVEVIEW":
						e_FileTypes = ConfigData.e_FileTypes.LIVEVIEW;
						break;
					case "LIVEVIEW_CONFIG":
						e_FileTypes = ConfigData.e_FileTypes.LIVEVIEW_CFG;
						break;
					}
				}
				xmlReader.Close();
				return e_FileTypes;
			}
			catch
			{
				xmlReader.Close();
				return ConfigData.e_FileTypes.INVALID;
			}
		}

		public void CreateLog(string logpath, string root)
		{
			this.logpath = logpath;
			shortlogpath = Path.GetFileNameWithoutExtension(logpath);
			XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
			xmlWriterSettings.Encoding = Encoding.UTF8;
			xmlWriterSettings.Indent = false;
			xmlWriterSettings.NewLineOnAttributes = false;
			writer = XmlWriter.Create(logpath, xmlWriterSettings);
			writer.WriteStartDocument();
			writer.WriteStartElement(root);
		}

		public void CreateLogStream(MemoryStream fstream, string root, bool linebreaks)
		{
			XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
			xmlWriterSettings.Encoding = Encoding.UTF8;
			xmlWriterSettings.Indent = linebreaks;
			xmlWriterSettings.NewLineOnAttributes = linebreaks;
			writer = XmlWriter.Create(fstream, xmlWriterSettings);
			writer.WriteStartDocument();
			writer.WriteStartElement(root);
		}

		public void CreateLogStream(string root, bool linebreaks)
		{
			myStream = new MemoryStream();
			XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();
			xmlWriterSettings.Encoding = Encoding.UTF8;
			xmlWriterSettings.Indent = linebreaks;
			xmlWriterSettings.NewLineOnAttributes = linebreaks;
			writer = XmlWriter.Create(myStream, xmlWriterSettings);
			writer.WriteStartDocument();
			writer.WriteStartElement(root);
		}

		public void WriteStartElement(string element, string comment)
		{
			writer.WriteComment(comment);
			writer.WriteStartElement(element);
		}

		public void WriteEndElement()
		{
			writer.WriteEndElement();
		}

		public void Close()
		{
			if (writer != null)
			{
				writer.Close();
			}
		}

		public bool IsClosed()
		{
			bool result = false;
			if (writer != null && (writer.WriteState == WriteState.Closed || writer.WriteState == WriteState.Error))
			{
				result = true;
			}
			return result;
		}

		public void EndLog()
		{
			writer.WriteEndElement();
			writer.WriteEndDocument();
			writer.Flush();
			writer.Close();
		}

		public void EndLog_KeepStreamUp()
		{
			writer.WriteEndElement();
			writer.WriteEndDocument();
			writer.Flush();
		}

		public void ReadStatistics(XmlReader reader, ref string[,] statsAndHeaderA, ref string[,] statsAndHeaderB)
		{
			string text = string.Empty;
			string[,] array = new string[8, 14];
			int num = 0;
			reader.ReadToFollowing("STATISTICS");
			bool flag = true;
			reader.ReadToFollowing("STAT_ECU");
			while (reader.Read() && flag)
			{
				if (reader.IsStartElement())
				{
					switch (reader.Name)
					{
					case "STAT_ECU_UNIT":
						if (reader.Read())
						{
							text = reader.Value;
						}
						break;
					case "STAT_TIMER_NUMBER":
						if (reader.Read())
						{
							num = int.Parse(reader.Value);
						}
						break;
					case "STAT_NAME":
						if (reader.Read())
						{
							array[num, 8] = reader.Value;
						}
						break;
					case "STAT_SIGNAL":
						if (reader.Read())
						{
							array[num, 9] = reader.Value;
						}
						break;
					case "STAT_UNIT":
						if (reader.Read())
						{
							array[num, 10] = reader.Value;
						}
						break;
					case "STAT_RANGE_Low":
						if (reader.Read())
						{
							array[num, 11] = reader.Value;
						}
						break;
					case "STAT_RANGE_High":
						if (reader.Read())
						{
							array[num, 12] = reader.Value;
						}
						break;
					case "STAT_RANGEDiv":
						if (reader.Read())
						{
							array[num, 13] = reader.Value;
						}
						break;
					case "STAT_ELEMENT0":
						if (reader.Read())
						{
							array[num, 0] = reader.Value;
						}
						break;
					case "STAT_ELEMENT1":
						if (reader.Read())
						{
							array[num, 1] = reader.Value;
						}
						break;
					case "STAT_ELEMENT2":
						if (reader.Read())
						{
							array[num, 2] = reader.Value;
						}
						break;
					case "STAT_ELEMENT3":
						if (reader.Read())
						{
							array[num, 3] = reader.Value;
						}
						break;
					case "STAT_ELEMENT4":
						if (reader.Read())
						{
							array[num, 4] = reader.Value;
						}
						break;
					case "STAT_ELEMENT5":
						if (reader.Read())
						{
							array[num, 5] = reader.Value;
						}
						break;
					case "STAT_ELEMENT6":
						if (reader.Read())
						{
							array[num, 6] = reader.Value;
						}
						break;
					case "STAT_ELEMENT7":
						if (reader.Read())
						{
							array[num, 7] = reader.Value;
						}
						break;
					}
					continue;
				}
				switch (reader.Name)
				{
				case "STAT_ECU":
					if (text == "A")
					{
						statsAndHeaderA = array;
					}
					else if (text == "B")
					{
						statsAndHeaderB = array;
					}
					array = new string[8, 14];
					break;
				case "STATISTICS":
					flag = false;
					break;
				}
			}
		}

		public void SaveStatistics(object[,] timer, string AB)
		{
			writer.WriteStartElement("STAT_ECU");
			writer.WriteElementString("STAT_ECU_UNIT", AB);
			for (int i = 0; i < 8; i++)
			{
				writer.WriteStartElement("STAT_TIMER");
				writer.WriteElementString("STAT_TIMER_NUMBER", i.ToString());
				writer.WriteElementString("STAT_NAME", (string)timer[i, 8]);
				writer.WriteElementString("STAT_SIGNAL", (string)timer[i, 9]);
				writer.WriteElementString("STAT_UNIT", (string)timer[i, 10]);
				writer.WriteElementString("STAT_RANGE_Low", (string)timer[i, 11]);
				writer.WriteElementString("STAT_RANGE_High", (string)timer[i, 12]);
				writer.WriteElementString("STAT_RANGEDiv", timer[i, 13].ToString());
				writer.WriteElementString("STAT_ELEMENT0", timer[i, 0].ToString());
				writer.WriteElementString("STAT_ELEMENT1", timer[i, 1].ToString());
				writer.WriteElementString("STAT_ELEMENT2", timer[i, 2].ToString());
				writer.WriteElementString("STAT_ELEMENT3", timer[i, 3].ToString());
				writer.WriteElementString("STAT_ELEMENT4", timer[i, 4].ToString());
				writer.WriteElementString("STAT_ELEMENT5", timer[i, 5].ToString());
				writer.WriteElementString("STAT_ELEMENT6", timer[i, 6].ToString());
				writer.WriteElementString("STAT_ELEMENT7", timer[i, 7].ToString());
				writer.WriteEndElement();
			}
			writer.WriteEndElement();
		}

		public void DTCLoad(XmlReader inXmlRead, ref List<DTC> dtcListA, ref List<DTC> dtcListB)
		{
			int id = 0;
			int errTyp_first = 0;
			int errTyp_last = 0;
			int freq = 0;
			string text = string.Empty;
			int num = 0;
			bool flag = true;
			string[] array = new string[9];
			string[] array2 = new string[9];
			string[] array3 = new string[9];
			string[] array4 = new string[9];
			string cl = string.Empty;
			string active = string.Empty;
			string text2 = string.Empty;
			string text3 = string.Empty;
			string text4 = string.Empty;
			string text5 = string.Empty;
			inXmlRead.ReadToFollowing("FAULT_CODE_MEMORY");
			while (inXmlRead.Read() && flag)
			{
				if (inXmlRead.IsStartElement())
				{
					switch (inXmlRead.Name)
					{
					case "FCM_ECU_UNIT":
						if (inXmlRead.Read())
						{
							text = inXmlRead.Value;
						}
						break;
					case "FCM_ENTRY":
					{
						for (int i = 0; i < 9; i++)
						{
							array[i] = string.Empty;
							array2[i] = string.Empty;
							array3[i] = string.Empty;
							array4[i] = string.Empty;
						}
						break;
					}
					case "FCM_ENTRY_NUMBER":
						if (inXmlRead.Read())
						{
							int.Parse(inXmlRead.Value);
						}
						break;
					case "FCM_ENTRY_STATUS":
						if (inXmlRead.Read())
						{
							active = inXmlRead.Value;
						}
						break;
					case "FCM_ENTRY_MIL":
						if (inXmlRead.Read())
						{
							cl = inXmlRead.Value;
						}
						break;
					case "FCM_DTC":
						if (inXmlRead.Read())
						{
							id = Convert.ToInt32(inXmlRead.Value, 16);
						}
						break;
					case "FCM_FREQ":
						if (inXmlRead.Read())
						{
							freq = int.Parse(inXmlRead.Value);
						}
						break;
					case "FCM_TYPE_FIRST":
						if (inXmlRead.Read())
						{
							errTyp_first = int.Parse(inXmlRead.Value);
						}
						break;
					case "FCM_TYPE_LAST":
						if (inXmlRead.Read())
						{
							errTyp_last = int.Parse(inXmlRead.Value);
						}
						break;
					case "FCM_ENV":
						text2 = string.Empty;
						text3 = string.Empty;
						text4 = string.Empty;
						text5 = string.Empty;
						break;
					case "FCM_ENV_CONDITION":
						if (inXmlRead.Read())
						{
							num = int.Parse(inXmlRead.Value);
						}
						break;
					case "FCM_ENV_COND_DESC":
						if (inXmlRead.Read())
						{
							text4 = inXmlRead.Value;
						}
						break;
					case "FCM_ENV_COND_PHYS_FIRST":
						if (inXmlRead.Read())
						{
							text2 = inXmlRead.Value;
						}
						break;
					case "FCM_ENV_COND_PHYS_LAST":
						if (inXmlRead.Read())
						{
							text3 = inXmlRead.Value;
						}
						break;
					case "FCM_ENV_COND_UNITS":
						if (inXmlRead.Read())
						{
							if (inXmlRead.Name != "FCM_ENV")
							{
								text5 = inXmlRead.Value;
								break;
							}
							text5 = "";
							array[num - 1] = text2;
							array2[num - 1] = text3;
							array4[num - 1] = text5;
							array3[num - 1] = text4;
						}
						break;
					}
					continue;
				}
				switch (inXmlRead.Name)
				{
				case "FCM_ENV":
					if (num > 0 && num < 10)
					{
						array[num - 1] = text2;
						array2[num - 1] = text3;
						array4[num - 1] = text5;
						array3[num - 1] = text4;
					}
					break;
				case "FCM_ENTRY":
				{
					DTC dTC = ConfigData.GetDTC(id);
					if (text == "A")
					{
						dtcListA.Add(dTC.CloneNewStatusXML(errTyp_first, errTyp_last, active, cl, freq, array, array2, array3, array4));
					}
					else if (text == "B")
					{
						dtcListB.Add(dTC.CloneNewStatusXML(errTyp_first, errTyp_last, active, cl, freq, array, array2, array3, array4));
					}
					break;
				}
				case "FAULT_CODE_MEMORY":
					flag = false;
					break;
				}
			}
		}

		private string ReadXMLString(XmlReader r, string elementName, string ECU)
		{
			if (!(ECU == "A") && !(ECU == "B"))
			{
				throw new Exception("ECU string must be A or B");
			}
			if (!r.ReadToFollowing(elementName))
			{
				throw new Exception("Element: " + elementName + " for ECU " + ECU + " not found");
			}
			r.Read();
			return r.ReadContentAsString();
		}

		public void SaveDTC(DTC[] dtc, string AB)
		{
			try
			{
				writer.WriteStartElement("FCM_ECU");
				writer.WriteElementString("FCM_ECU_UNIT", AB);
				int num = 0;
				foreach (DTC dTC in dtc)
				{
					if (dTC != null)
					{
						writer.WriteStartElement("FCM_ENTRY");
						writer.WriteElementString("FCM_ENTRY_NUMBER", num.ToString());
						writer.WriteElementString("FCM_ENTRY_STATUS", dTC.statusText);
						writer.WriteElementString("FCM_ENTRY_MIL", dTC.cautionlampText);
						writer.WriteElementString("FCM_DTC", string.Format("{0:x4}", dTC.id));
						writer.WriteElementString("FCM_DTC_TEXT", dTC.displaytext);
						writer.WriteElementString("FCM_DTC_DFP", dTC.signal);
						writer.WriteElementString("FCM_FREQ", dTC.freq.ToString());
						writer.WriteElementString("FCM_TYPE_FIRST", dTC.ErrTyp_first.ToString());
						writer.WriteElementString("FCM_TYPE_TEXT_FIRST", dTC.ErrTyp_firstText);
						writer.WriteElementString("FCM_TYPE_LAST", dTC.ErrTyp_last.ToString());
						writer.WriteElementString("FCM_TYPE_TEXT_LAST", dTC.ErrTyp_lastText);
						for (int j = 0; j < 9; j++)
						{
							DTC.Env env = dTC.vals[j];
							writer.WriteStartElement("FCM_ENV");
							writer.WriteElementString("FCM_ENV_CONDITION", (j + 1).ToString());
							writer.WriteElementString("FCM_ENV_COND_SIGNAL", env.Env_Signal);
							writer.WriteElementString("FCM_ENV_COND_DESC", env.Env_Description);
							writer.WriteElementString("FCM_ENV_COND_PHYS_FIRST", env.Env_first_value);
							writer.WriteElementString("FCM_ENV_COND_PHYS_LAST", env.Env_last_value);
							writer.WriteElementString("FCM_ENV_COND_UNITS", ConfigData.SigClass[(int)env.Env_Class].GetUnitStr());
							writer.WriteEndElement();
						}
						writer.WriteEndElement();
					}
					num++;
				}
				writer.WriteEndElement();
			}
			catch
			{
				MessageBox.Show("SaveDTC not OK");
			}
		}

		public void FileID(string filename)
		{
			writer.WriteComment("Description of Logfile");
			writer.WriteStartElement("FILE_ID");
			writer.WriteElementString("FILE_NAME", filename);
			writer.WriteStartElement("FILE_CREATION");
			DateTime utcNow = DateTime.UtcNow;
			writer.WriteElementString("DAY", utcNow.ToString("dd"));
			writer.WriteElementString("MONTH", utcNow.ToString("MM"));
			writer.WriteElementString("YEAR", utcNow.ToString("yyyy"));
			writer.WriteElementString("HOUR", utcNow.ToString("HH"));
			writer.WriteElementString("MINUTE", utcNow.ToString("mm"));
			writer.WriteElementString("SECOND", utcNow.ToString("ss"));
			writer.WriteEndElement();
			writer.WriteEndElement();
		}

		public DateTime ReadFileTimeStamp(XmlReader reader)
		{
			DateTime dateTime = default(DateTime);
			int num = 0;
			if (!reader.ReadToFollowing("FILE_ID"))
			{
				throw new Exception("Internal: no timestamp in file");
			}
			if (!reader.ReadToFollowing("FILE_CREATION"))
			{
				throw new Exception("Internal: no timestamp in file");
			}
			reader.ReadToFollowing("DAY");
			reader.Read();
			int day = reader.ReadContentAsInt();
			reader.ReadToFollowing("MONTH");
			reader.Read();
			int month = reader.ReadContentAsInt();
			reader.ReadToFollowing("YEAR");
			reader.Read();
			int year = reader.ReadContentAsInt();
			reader.ReadToFollowing("HOUR");
			reader.Read();
			int hour = reader.ReadContentAsInt();
			reader.ReadToFollowing("MINUTE");
			reader.Read();
			int minute = reader.ReadContentAsInt();
			reader.ReadToFollowing("SECOND");
			reader.Read();
			num = reader.ReadContentAsInt();
			return new DateTime(year, month, day, hour, minute, num);
		}

		public void SwID(string SwName, string SwVersion, string Manufacturer, string EcuStr)
		{
			writer.WriteComment("Description of Wizard");
			writer.WriteStartElement("SW_ID");
			writer.WriteElementString("SW_NAME", SwName);
			writer.WriteElementString("SW_VERSION", SwVersion);
			writer.WriteElementString("SW_VERSION_ECU", EcuStr);
			writer.WriteStartElement("SW_INSTALLATION");
			string text = "not set";
			string keyName = "HKEY_LOCAL_MACHINE\\Software\\" + Manufacturer + "\\" + SwName;
			string text2 = (string)Registry.GetValue(keyName, "InstallationDate", text);
			if (text2 != "not set" && text2 != null)
			{
				DateTime dateTime = Convert.ToDateTime(text2);
				writer.WriteElementString("DAY", dateTime.ToString("dd"));
				writer.WriteElementString("MONTH", dateTime.ToString("MM"));
				writer.WriteElementString("YEAR", dateTime.ToString("yyyy"));
			}
			else
			{
				writer.WriteElementString("DAY", text);
				writer.WriteElementString("MONTH", text);
				writer.WriteElementString("YEAR", text);
			}
			writer.WriteEndElement();
			writer.WriteEndElement();
		}

		public void UserID()
		{
			writer.WriteComment("Description of Wizard-User");
			writer.WriteStartElement("USER_ID");
			writer.WriteElementString("USER_COMPANY", Environment.UserDomainName);
			writer.WriteElementString("USER_NAME", Environment.MachineName);
			writer.WriteElementString("USER_LOGIN", Environment.UserName);
			writer.WriteElementString("USER_NUMBER", Environment.UserName);
			writer.WriteEndElement();
		}

		public string[] ReadEngineID(Stream ms, string ECU)
		{
			string[] array = new string[6];
			if (!(ECU == "A") && !(ECU == "B"))
			{
				return array;
			}
			XmlReader xmlReader = XmlReader.Create(ms);
			xmlReader.ReadToFollowing("ENGINE_ID");
			try
			{
				xmlReader.ReadToFollowing("ENGINE_TYPE_" + ECU);
				xmlReader.Read();
				array[0] = xmlReader.ReadContentAsString();
			}
			catch
			{
				array[0] = "not available";
			}
			try
			{
				xmlReader.ReadToFollowing("ENGINE_SERIAL_" + ECU);
				xmlReader.Read();
				array[1] = xmlReader.ReadContentAsString();
			}
			catch
			{
				array[1] = "not available";
			}
			try
			{
				xmlReader.ReadToFollowing("ENGINE_TIME_" + ECU);
				xmlReader.Read();
				array[2] = xmlReader.ReadContentAsString();
			}
			catch
			{
				array[2] = "not available";
			}
			xmlReader.Close();
			return array;
		}

		public void SaveEngineID(IECU_Data datA, IECU_Data datB)
		{
			writer.WriteComment("Description of Engine");
			writer.WriteStartElement("ENGINE_ID");
			writer.WriteElementString("ENGINE_TYPE_A", datA.EngineType);
			writer.WriteElementString("ENGINE_TYPE_B", datB.EngineType);
			writer.WriteElementString("ENGINE_SERIAL_A", datA.EngineSerialNumber);
			writer.WriteElementString("ENGINE_SERIAL_B", datB.EngineSerialNumber);
			writer.WriteElementString("ENGINE_TIME_A", datA.TotalEngineTime);
			writer.WriteElementString("ENGINE_TIME_B", datB.TotalEngineTime);
			writer.WriteEndElement();
			writer.WriteComment("Description of EECU");
			writer.WriteStartElement("EECU_ID");
			writer.WriteElementString("EECU_TYPE", "E4A-92-000-000");
			writer.WriteElementString("EECU_SERIAL_A", datA.EcuSerialNumber);
			writer.WriteElementString("EECU_SERIAL_B", datB.EcuSerialNumber);
			writer.WriteElementString("EECU_HWREV_A", datA.EcuHwVersionReadable);
			writer.WriteElementString("EECU_HWREV_B", datB.EcuHwVersionReadable);
			writer.WriteElementString("EECU_SWREV_A", datA.EcuSwVersion);
			writer.WriteElementString("EECU_SWREV_B", datB.EcuSwVersion);
			writer.WriteElementString("EECU_TotTimeECUA", datA.TotalECUPwrOnTime);
			writer.WriteElementString("EECU_TotTimeActECUA", datA.TotalECUEngineControlTime);
			writer.WriteElementString("EECU_TotTimeECUB", datB.TotalECUPwrOnTime);
			writer.WriteElementString("EECU_TotTimeActECUB", datB.TotalECUEngineControlTime);
			writer.WriteElementString("EECU_RTC_ECUA", datA.RealTimeClock_string);
			writer.WriteElementString("EECU_RTC_ECUB", datB.RealTimeClock_string);
			writer.WriteEndElement();
		}

		public string[] ReadEECUID(Stream msx, string ECU)
		{
			string[] array = new string[7]
			{
				string.Empty,
				string.Empty,
				string.Empty,
				string.Empty,
				string.Empty,
				string.Empty,
				string.Empty
			};
			bool flag = true;
			if (!(ECU == "A") && !(ECU == "B"))
			{
				return array;
			}
			XmlReader xmlReader = XmlReader.Create(msx);
			try
			{
				while (xmlReader.Read() && flag)
				{
					string name;
					if (xmlReader.IsStartElement())
					{
						if (ECU == "A")
						{
							switch (xmlReader.Name)
							{
							case "EECU_TYPE":
								if (xmlReader.Read())
								{
									array[0] = xmlReader.ReadContentAsString();
								}
								break;
							case "EECU_SERIAL_A":
								if (xmlReader.Read())
								{
									array[1] = xmlReader.ReadContentAsString();
								}
								break;
							case "EECU_HWREV_A":
								if (xmlReader.Read())
								{
									array[2] = xmlReader.ReadContentAsString();
								}
								break;
							case "EECU_SWREV_A":
								if (xmlReader.Read())
								{
									array[3] = xmlReader.ReadContentAsString();
								}
								break;
							case "EECU_TotTimeECUA":
								if (xmlReader.Read())
								{
									array[4] = xmlReader.ReadContentAsString();
								}
								break;
							case "EECU_TotTimeActECUA":
								if (xmlReader.Read())
								{
									array[5] = xmlReader.ReadContentAsString();
								}
								break;
							case "EECU_RTC_ECUA":
								if (xmlReader.Read())
								{
									array[6] = xmlReader.ReadContentAsString();
								}
								break;
							}
							continue;
						}
						switch (xmlReader.Name)
						{
						case "EECU_TYPE":
							if (xmlReader.Read())
							{
								array[0] = xmlReader.ReadContentAsString();
							}
							break;
						case "EECU_SERIAL_B":
							if (xmlReader.Read())
							{
								array[1] = xmlReader.ReadContentAsString();
							}
							break;
						case "EECU_HWREV_B":
							if (xmlReader.Read())
							{
								array[2] = xmlReader.ReadContentAsString();
							}
							break;
						case "EECU_SWREV_B":
							if (xmlReader.Read())
							{
								array[3] = xmlReader.ReadContentAsString();
							}
							break;
						case "EECU_TotTimeECUB":
							if (xmlReader.Read())
							{
								array[4] = xmlReader.ReadContentAsString();
							}
							break;
						case "EECU_TotTimeActECUB":
							if (xmlReader.Read())
							{
								array[5] = xmlReader.ReadContentAsString();
							}
							break;
						case "EECU_RTC_ECUB":
							if (xmlReader.Read())
							{
								array[6] = xmlReader.ReadContentAsString();
							}
							break;
						}
					}
					else if ((name = xmlReader.Name) != null && name == "EECU_ID")
					{
						flag = false;
					}
				}
			}
			catch
			{
			}
			return array;
		}

		public void IQAScannedCode(string[] IQA)
		{
			writer.WriteComment("Section IQA-Codes");
			writer.WriteStartElement("IQA_CODES");
			writer.WriteElementString("Cyl1", IQA[0]);
			writer.WriteElementString("Cyl2", IQA[1]);
			writer.WriteElementString("Cyl3", IQA[2]);
			writer.WriteElementString("Cyl4", IQA[3]);
			writer.WriteEndElement();
		}

		public void IQACode(string[] IQA_A, string[] IQA_B)
		{
			writer.WriteComment("Section IQA-Codes");
			writer.WriteStartElement("IQA_CODES");
			writer.WriteStartElement("IQA_CODE_ECU");
			writer.WriteElementString("IQA_CODE_ECU_UNIT", "A");
			writer.WriteElementString("Cyl1", IQA_A[0]);
			writer.WriteElementString("Cyl2", IQA_A[1]);
			writer.WriteElementString("Cyl3", IQA_A[2]);
			writer.WriteElementString("Cyl4", IQA_A[3]);
			writer.WriteEndElement();
			writer.WriteStartElement("IQA_CODE_ECU");
			writer.WriteElementString("IQA_CODE_ECU_UNIT", "B");
			writer.WriteElementString("Cyl1", IQA_B[0]);
			writer.WriteElementString("Cyl2", IQA_B[1]);
			writer.WriteElementString("Cyl3", IQA_B[2]);
			writer.WriteElementString("Cyl4", IQA_B[3]);
			writer.WriteEndElement();
			writer.WriteEndElement();
		}

		public void SaveDataLog(ArrayList functs)
		{
			writer.WriteComment("Section DataLogger Entries");
			try
			{
				char[] array = new char[2] { 'A', 'B' };
				char[] array2 = array;
				for (int i = 0; i < array2.Length; i++)
				{
					char c = array2[i];
					writer.WriteStartElement("SIGNALS", c.ToString());
					foreach (Function funct in functs)
					{
						if (!funct.name.StartsWith(c + ":"))
						{
							continue;
						}
						string name = funct.name;
						name = name.Replace(": ", "_");
						name = name.Replace(' ', '_');
						name = Regex.Replace(name, "[^0-9a-zA-Z._-]", "_");
						writer.WriteStartElement("SIGNAL");
						writer.WriteAttributeString("NAME", name);
						writer.WriteStartElement("KOORD");
						writer.WriteAttributeString("X_MIN", funct.koordsyst.XMin.ToString());
						writer.WriteAttributeString("X_MAX", funct.koordsyst.XMax.ToString());
						writer.WriteAttributeString("Y_MIN", funct.koordsyst.YMin.ToString());
						writer.WriteAttributeString("Y_MAX", funct.koordsyst.YMax.ToString());
						writer.WriteAttributeString("YSCAL", ((float)funct.koordsyst.YScal).ToString());
						writer.WriteAttributeString("UNIT", funct.koordsyst.YAxeText);
						writer.WriteAttributeString("COL", funct.koordsyst.KoordColor.Name);
						writer.WriteEndElement();
						writer.WriteStartElement("POINTS");
						for (int j = 0; j < funct.points.Count; j++)
						{
							writer.WriteStartElement("PT");
							writer.WriteAttributeString("X", funct.points[j].X.ToString());
							writer.WriteAttributeString("Y", funct.points[j].Y.ToString());
							writer.WriteAttributeString("T", ((DateTime)funct.timestamps[j]/*cast due to .constrained prefix*/).ToString());
							if (funct.sessionMarkers[funct.points[j]] != null)
							{
								DateTime dateTime = (DateTime)funct.sessionMarkers[funct.points[j]];
								writer.WriteAttributeString("SM", dateTime.ToString());
							}
							else
							{
								writer.WriteAttributeString("SM", "");
							}
							string value = string.Empty;
							if (funct.SessionMarkerComment[funct.points[j]] != null)
							{
								value = (string)funct.SessionMarkerComment[funct.points[j]];
							}
							writer.WriteAttributeString("SMC", value);
							writer.WriteEndElement();
						}
						writer.WriteEndElement();
						writer.WriteEndElement();
					}
					writer.WriteEndElement();
				}
			}
			catch
			{
			}
		}

		public void EventRec(ArrayList EvRec_A, ArrayList EvRec_B)
		{
			writer.WriteComment("Section EventRecorder Entries");
			try
			{
				writer.WriteStartElement("EVENTS", "A");
				foreach (EventLogEntry item in EvRec_A)
				{
					object[] array = item.createRow();
					writer.WriteStartElement("EVENT", "A");
					writer.WriteAttributeString("TIMESTAMP", array[0].ToString());
					writer.WriteAttributeString("DTC", array[1].ToString());
					writer.WriteAttributeString("STATUS", array[2].ToString());
					writer.WriteAttributeString("EVENTCOUNT", array[3].ToString());
					writer.WriteAttributeString("DESCRIPTION", array[4].ToString());
					writer.WriteEndElement();
				}
				writer.WriteEndElement();
			}
			catch
			{
			}
			try
			{
				writer.WriteStartElement("EVENTS", "B");
				foreach (EventLogEntry item2 in EvRec_B)
				{
					object[] array2 = item2.createRow();
					writer.WriteStartElement("EVENT", "B");
					writer.WriteAttributeString("TIMESTAMP", array2[0].ToString());
					writer.WriteAttributeString("DTC", array2[1].ToString());
					writer.WriteAttributeString("STATUS", array2[2].ToString());
					writer.WriteAttributeString("EVENTCOUNT", array2[3].ToString());
					writer.WriteAttributeString("DESCRIPTION", array2[4].ToString());
					writer.WriteEndElement();
				}
				writer.WriteEndElement();
			}
			catch
			{
			}
		}

		public void SaveRecManStatus(RecManStatus status, string AB)
		{
			writer.WriteComment("RecMan Status ECU " + AB);
			writer.WriteStartElement("STATUS", AB);
			writer.WriteAttributeString("ENTRY_CNT", status.EvRecEntryCnt.ToString());
			writer.WriteAttributeString("ACTIVE_EVREC", status.ActiveEvRec.ToString());
			writer.WriteAttributeString("ACTIVE_DATLOG", status.ActiveDatLog.ToString());
			writer.WriteEndElement();
		}

		public RecManStatus ReadRecManStatus(XmlReader root, string ECU)
		{
			if (!(ECU == "A") && !(ECU == "B"))
			{
				throw new ArgumentException("Parameter ECU must be A or B");
			}
			new List<RecManBase.RecManSector>();
			return new RecManStatus(Convert.ToInt32(root.GetAttribute("ENTRY_CNT")), Convert.ToInt32(root.GetAttribute("ACTIVE_EVREC")), Convert.ToInt32(root.GetAttribute("ACTIVE_DATLOG")));
		}

		public void SaveRecManSectors(ref List<RecManBase.RecManSector> sectors, string AB)
		{
			writer.WriteComment("Section RecMan Sectors ECU " + AB);
			writer.WriteStartElement("SECTORS", AB);
			try
			{
				foreach (RecManBase.RecManSector sector in sectors)
				{
					writer.WriteStartElement("SECTOR");
					writer.WriteStartElement("ID");
					writer.WriteValue(sector.ID);
					writer.WriteEndElement();
					writer.WriteStartElement("DATA");
					for (int i = 0; i < sector.DataRaw.Count; i++)
					{
						writer.WriteStartElement("B");
						writer.WriteValue(sector.DataRaw[i]);
						writer.WriteEndElement();
					}
					writer.WriteEndElement();
					writer.WriteEndElement();
				}
			}
			catch (Exception)
			{
				MessageBox.Show("Error during XML_Log export of RecManSectors", ConfigData.WizardSwName);
			}
			writer.WriteEndElement();
		}

		public void ReadIQA(XmlReader reader, ref string[] IQACylValA, ref string[] IQACylValB)
		{
			bool flag = true;
			string text = string.Empty;
			reader.ReadToFollowing("IQA_CODES");
			while (reader.Read() && flag)
			{
				if (reader.IsStartElement())
				{
					switch (reader.Name)
					{
					case "IQA_CODE_ECU_UNIT":
						if (reader.Read())
						{
							text = reader.Value;
						}
						break;
					case "Cyl1":
						if (reader.Read())
						{
							if (text == "A")
							{
								IQACylValA[0] = reader.Value;
							}
							else if (text == "B")
							{
								IQACylValB[0] = reader.Value;
							}
						}
						break;
					case "Cyl2":
						if (reader.Read())
						{
							if (text == "A")
							{
								IQACylValA[1] = reader.Value;
							}
							else if (text == "B")
							{
								IQACylValB[1] = reader.Value;
							}
						}
						break;
					case "Cyl3":
						if (reader.Read())
						{
							if (text == "A")
							{
								IQACylValA[2] = reader.Value;
							}
							else if (text == "B")
							{
								IQACylValB[2] = reader.Value;
							}
						}
						break;
					case "Cyl4":
						if (reader.Read())
						{
							if (text == "A")
							{
								IQACylValA[3] = reader.Value;
							}
							else if (text == "B")
							{
								IQACylValB[3] = reader.Value;
							}
						}
						break;
					}
				}
				else if (reader.Name == "IQA_CODES")
				{
					flag = false;
				}
			}
		}

		public string[] ReadIQA(Stream input)
		{
			string[] array = new string[8];
			XmlReader xmlReader = XmlReader.Create(input);
			Xml_Log xml_Log = new Xml_Log();
			switch (xml_Log.ReadFiletype(input))
			{
			case ConfigData.e_FileTypes.IQA:
				xmlReader.ReadToFollowing("Cyl1");
				array[0] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl2");
				array[1] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl3");
				array[2] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl4");
				array[3] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl1");
				array[4] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl2");
				array[5] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl3");
				array[6] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl4");
				array[7] = xmlReader.ReadString();
				break;
			case ConfigData.e_FileTypes.IQA_STORAGE:
				xmlReader.ReadToFollowing("Cyl1");
				array[0] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl2");
				array[1] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl3");
				array[2] = xmlReader.ReadString();
				xmlReader.ReadToFollowing("Cyl4");
				array[3] = xmlReader.ReadString();
				array[4] = array[0];
				array[5] = array[1];
				array[6] = array[2];
				array[7] = array[3];
				break;
			}
			return array;
		}

		public List<RecManBase.RecManSector> ReadRecManHexDump(XmlReader root, string ECU)
		{
			if (!(ECU == "A") && !(ECU == "B"))
			{
				throw new ArgumentException("Parameter ECU must be A or B");
			}
			List<RecManBase.RecManSector> list = new List<RecManBase.RecManSector>();
			root.ReadToFollowing("SECTORS", ECU);
			while (root.ReadToFollowing("SECTOR", ECU) && !root.EOF && root.ReadToFollowing("ID", ECU))
			{
				root.Read();
				int num = root.ReadContentAsInt();
				if (this.ev_ProgressStep != null)
				{
					this.ev_ProgressStep(this, new ServiceLayerStringEventArg(string.Format("Read sector {0} ECU{1}", num, ECU)));
				}
				if (!root.ReadToFollowing("DATA", ECU))
				{
					break;
				}
				List<byte> dataRaw = new List<byte>(65538);
				XmlReader xmlReader = root.ReadSubtree();
				if (!xmlReader.ReadToFollowing("DATA", ECU))
				{
					break;
				}
				while (xmlReader.ReadToFollowing("B", ECU))
				{
					root.Read();
					byte item = Convert.ToByte(xmlReader.ReadContentAsString());
					dataRaw.Add(item);
				}
				RecManBase.RecManSector item2 = new RecManBase.RecManSector(num, ref dataRaw, true);
				list.Add(item2);
			}
			return list;
		}

		public void SaveLiveViewHeader()
		{
			if (!IsClosed())
			{
				writer.WriteStartElement("RECORDDATA");
			}
		}

		public void SaveLiveViewFooter()
		{
			if (IsClosed())
			{
				return;
			}
			try
			{
				writer.WriteEndElement();
				writer.WriteEndElement();
			}
			catch
			{
			}
		}

		public void SaveLiveViewSamplesHeader()
		{
			if (!IsClosed())
			{
				writer.WriteStartElement("SAMPLES");
			}
		}

		public void SaveLiveViewSample(ref List<float> sampleValues, ref string AB)
		{
			if (IsClosed())
			{
				return;
			}
			try
			{
				writer.WriteStartElement("SPL", AB);
				foreach (float sampleValue in sampleValues)
				{
					float value = sampleValue;
					writer.WriteStartElement("V");
					writer.WriteValue(value);
					writer.WriteEndElement();
				}
				writer.WriteEndElement();
			}
			catch (Exception ex)
			{
				MessageBox.Show(string.Format("Error during XML_Log export of LiveViewSample, {0}; Er:{1}", ConfigData.WizardSwName, ex.Message));
			}
		}

		public void SaveLiveViewRecordInterval(int interval, string AB)
		{
			if (!IsClosed())
			{
				writer.WriteStartElement("RECORD_INTERVAL", AB);
				try
				{
					writer.WriteValue(interval);
				}
				catch (Exception)
				{
					MessageBox.Show("Error during XML_Log export of LiveViewB RecordInterval", ConfigData.WizardSwName);
				}
				writer.WriteEndElement();
			}
		}

		public void SaveLiveViewSignalDef(List<string> signalNames, string AB)
		{
			if (IsClosed())
			{
				return;
			}
			writer.WriteStartElement("SIGNAL_DEFINITIONS", AB);
			try
			{
				foreach (string signalName in signalNames)
				{
					writer.WriteStartElement("SIGNAL_NAME");
					writer.WriteValue(signalName);
					writer.WriteEndElement();
				}
			}
			catch (Exception)
			{
				MessageBox.Show("Error during XML_Log export of LiveViewB Signal Defintions", ConfigData.WizardSwName);
			}
			writer.WriteEndElement();
		}

		public void SaveLiveViewStartTime(string timeStr, string AB)
		{
			if (!IsClosed())
			{
				writer.WriteStartElement("LIVEVIEW_START", AB);
				writer.WriteValue(timeStr);
				writer.WriteEndElement();
			}
		}

		public void SaveLiveViewSignalDef(List<string> signalNames, string AB, string auxAddress, int auxMemSize)
		{
			if (IsClosed())
			{
				return;
			}
			writer.WriteStartElement("SIGNAL_DEFINITIONS", AB);
			try
			{
				foreach (string signalName in signalNames)
				{
					writer.WriteStartElement("SIGNAL_NAME");
					writer.WriteValue(signalName);
					writer.WriteEndElement();
				}
				writer.WriteStartElement("SIGNAL_NAME");
				writer.WriteAttributeString("ADDRESS", auxAddress);
				writer.WriteAttributeString("MEM_SIZE", auxMemSize.ToString());
				writer.WriteValue("Aux_signal");
				writer.WriteEndElement();
			}
			catch (Exception)
			{
				MessageBox.Show("Error during XML_Log export of LiveViewB Signal Defintions", ConfigData.WizardSwName);
			}
			writer.WriteEndElement();
		}

		public void SaveLiveViewConfig(List<string> signalNames, int recordInterval_ms, LogSignalLiveView auxSig, bool expert, string AB)
		{
			if (IsClosed())
			{
				return;
			}
			try
			{
				writer.WriteStartElement("LIVEVIEW_CONFIG", AB);
				writer.WriteStartElement("RECORD_INTERVAL", AB);
				writer.WriteValue(recordInterval_ms);
				writer.WriteEndElement();
				writer.WriteStartElement("EXPERT_MODE", AB);
				writer.WriteValue(expert);
				writer.WriteEndElement();
				writer.WriteStartElement("SIGNAL_DEFINITIONS", AB);
				foreach (string signalName in signalNames)
				{
					writer.WriteStartElement("SIGNAL_NAME", AB);
					writer.WriteValue(signalName);
					writer.WriteEndElement();
				}
				writer.WriteEndElement();
				if (auxSig != null)
				{
					string text = "";
					foreach (byte item in auxSig.Address)
					{
						text += string.Format("{0:X2}", item);
					}
					writer.WriteStartElement("AUX_SIGNAL", AB);
					writer.WriteAttributeString("ADDRESS", AB, text);
					writer.WriteAttributeString("MEMSIZE", AB, auxSig.MemSize.ToString());
					writer.WriteEndElement();
				}
				writer.WriteEndElement();
			}
			catch
			{
				MessageBox.Show("Error during XML_Log export of LiveView configuration", ConfigData.WizardSwName);
			}
		}

		public object[] ReadLiveViewConfig(XmlReader root, ConfigData.e_ECUID AB)
		{
			object[] array = new object[4];
			int num = 100;
			bool flag = true;
			List<string> list = new List<string>();
			string text = "";
			int num2 = 2;
			if (AB != ConfigData.e_ECUID.A && AB != ConfigData.e_ECUID.B)
			{
				throw new ArgumentException("Parameter AB must be A or B");
			}
			if (!root.ReadToFollowing("LIVEVIEW_CONFIG", ConfigData.ECUString[(int)AB]))
			{
				throw new Exception("no LIVEVIEW_CONFIG in file");
			}
			if (!root.ReadToFollowing("RECORD_INTERVAL", ConfigData.ECUString[(int)AB]))
			{
				throw new Exception("no RECORD_INTERVAL in file");
			}
			try
			{
				root.Read();
				num = Convert.ToInt32((uint)root.ReadContentAsInt());
			}
			catch
			{
				num = 100;
			}
			array[0] = num;
			if (!root.ReadToFollowing("EXPERT_MODE", ConfigData.ECUString[(int)AB]))
			{
				throw new Exception("no EXPERT_MODE selection in file");
			}
			try
			{
				root.Read();
				flag = root.ReadContentAsBoolean();
			}
			catch
			{
				flag = true;
			}
			array[3] = flag;
			if (!root.ReadToFollowing("SIGNAL_DEFINITIONS", ConfigData.ECUString[(int)AB]))
			{
				throw new Exception("no signals definition file");
			}
			XmlReader xmlReader = root.ReadSubtree();
			if (!xmlReader.ReadToFollowing("SIGNAL_DEFINITIONS", ConfigData.ECUString[(int)AB]))
			{
				throw new Exception("no signals definition in file");
			}
			while (xmlReader.ReadToFollowing("SIGNAL_NAME", ConfigData.ECUString[(int)AB]) && !xmlReader.EOF)
			{
				xmlReader.Read();
				string item = xmlReader.ReadContentAsString();
				list.Add(item);
			}
			array[1] = list;
			if (!root.ReadToFollowing("AUX_SIGNAL", ConfigData.ECUString[(int)AB]))
			{
				array[2] = null;
				return array;
			}
			LogSignalLiveView liveViewSignal_ByName = ConfigLiveView.GetLiveViewSignal_ByName("Aux_signal", ConfigData.e_ECUID.A);
			text = root.GetAttribute("ADDRESS", ConfigData.ECUString[(int)AB]);
			num2 = Convert.ToInt32(root.GetAttribute("MEMSIZE", ConfigData.ECUString[(int)AB]));
			liveViewSignal_ByName.ConfigureAuxSignal(text, num2);
			array[2] = liveViewSignal_ByName;
			return array;
		}

		public void ReadXmlFileLogInfo(XmlReader reader, ref CXmlFileLogInfo info)
		{
			string text = string.Empty;
			string text2 = string.Empty;
			string text3 = string.Empty;
			string text4 = string.Empty;
			string text5 = string.Empty;
			string text6 = string.Empty;
			bool flag = true;
			try
			{
				while (flag)
				{
					flag = reader.Read();
					if (reader.IsStartElement())
					{
						switch (reader.Name)
						{
						case "FILE_NAME":
							if (reader.Read())
							{
								info.filename = reader.Value.Trim();
							}
							break;
						case "DAY":
							if (reader.Read())
							{
								text = reader.Value.Trim();
							}
							break;
						case "MONTH":
							if (reader.Read())
							{
								text2 = reader.Value.Trim();
							}
							break;
						case "YEAR":
							if (reader.Read())
							{
								text3 = reader.Value.Trim();
							}
							break;
						case "MINUTE":
							if (reader.Read())
							{
								text5 = reader.Value.Trim();
							}
							break;
						case "HOUR":
							if (reader.Read())
							{
								text4 = reader.Value.Trim();
							}
							break;
						case "SECOND":
							if (reader.Read())
							{
								text6 = reader.Value.Trim();
							}
							break;
						case "SW_NAME":
							if (reader.Read())
							{
								info.swName = reader.Value.Trim();
							}
							break;
						case "SW_VERSION":
							if (reader.Read())
							{
								info.swVer = reader.Value.Trim();
							}
							break;
						case "SW_VERSION_ECU":
							if (reader.Read())
							{
								info.ecuSWVer = reader.Value.Trim();
							}
							break;
						case "ENGINE_TYPE_A":
							if (reader.Read())
							{
								info.engineTypeA = reader.Value.Trim();
							}
							break;
						case "ENGINE_TYPE_B":
							if (reader.Read())
							{
								info.engineTypeB = reader.Value.Trim();
							}
							break;
						case "ENGINE_SERIAL_A":
							if (reader.Read())
							{
								info.engineSerNrA = reader.Value.Trim();
							}
							break;
						case "ENGINE_SERIAL_B":
							if (reader.Read())
							{
								info.engineSerNrB = reader.Value.Trim();
							}
							break;
						case "ENGINE_TIME_A":
							if (reader.Read())
							{
								info.engineTimeA = reader.Value.Trim();
							}
							break;
						case "ENGINE_TIME_B":
							if (reader.Read())
							{
								info.engineTimeB = reader.Value.Trim();
							}
							break;
						case "EECU_TYPE":
							if (reader.Read())
							{
								info.ecuType = reader.Value.Trim();
							}
							break;
						case "EECU_SERIAL_A":
							if (reader.Read())
							{
								info.ecuSerialNrA = reader.Value.Trim();
							}
							break;
						case "EECU_SERIAL_B":
							if (reader.Read())
							{
								info.ecuSerialNrB = reader.Value.Trim();
							}
							break;
						case "EECU_HWREV_A":
							if (reader.Read())
							{
								info.ecuHWRevisionA = reader.Value.Trim();
							}
							break;
						case "EECU_HWREV_B":
							if (reader.Read())
							{
								info.ecuHWRevisionB = reader.Value.Trim();
							}
							break;
						case "EECU_SWREV_A":
							if (reader.Read())
							{
								info.ecuSWRevisionA = reader.Value.Trim();
							}
							break;
						case "EECU_SWREV_B":
							if (reader.Read())
							{
								info.ecuSWRevisionB = reader.Value.Trim();
							}
							break;
						case "EECU_TotTimeECUA":
							if (reader.Read())
							{
								info.ecuTotalActTimeA = reader.Value.Trim();
							}
							break;
						case "EECU_TotTimeECUB":
							if (reader.Read())
							{
								info.ecuTotalActTimeB = reader.Value.Trim();
							}
							break;
						case "EECU_RTC_ECUA":
							if (reader.Read())
							{
								info.ecuRTCA = reader.Value.Trim();
							}
							break;
						case "EECU_RTC_ECUB":
							if (reader.Read())
							{
								info.ecuRTCB = reader.Value.Trim();
							}
							break;
						}
					}
					else
					{
						switch (reader.Name)
						{
						case "FILE_CREATION":
							info.fileCreation = string.Format("{0}.{1}.{2} {3}:{4}:{5}", text, text2, text3, text4, text5, text6);
							break;
						case "EECU_ID":
							flag = false;
							break;
						}
					}
				}
			}
			catch (Exception ex)
			{
				string.Format("Error during XML import:\r\r\nFile contains no valid record manager sectors or is corrupt. {0}", ex.Message);
			}
		}

		public void ReadLiveViewXmlFilet(XmlReader reader, ref ServiceLayer.LiveViewStruct xmlData, List<LogSignalLiveView> liveViewSignalsA, List<LogSignalLiveView> liveViewSignalsB)
		{
			int day = 1;
			int month = 1;
			int year = 2017;
			int minute = 0;
			int hour = 0;
			int second = 0;
			List<float> list = new List<float>();
			ConfigData.e_ECUID e_ECUID = ConfigData.e_ECUID.A;
			list.Clear();
			try
			{
				while (reader.Read())
				{
					string value = reader.Value;
					string name = reader.Name;
					if (!reader.IsStartElement())
					{
						continue;
					}
					switch (reader.Name)
					{
					case "V":
						reader.Read();
						value = reader.Value;
						list.Add(reader.ReadContentAsFloat());
						break;
					case "SPL":
						value = reader.NamespaceURI;
						if (list.Count > 0)
						{
							switch (e_ECUID)
							{
							case ConfigData.e_ECUID.A:
								xmlData.samplesA.Add(list);
								break;
							case ConfigData.e_ECUID.B:
								xmlData.samplesB.Add(list);
								break;
							}
							list.Clear();
						}
						if (value == "A")
						{
							e_ECUID = ConfigData.e_ECUID.A;
						}
						else if (value == "B")
						{
							e_ECUID = ConfigData.e_ECUID.B;
						}
						break;
					case "SIGNAL_NAME":
						reader.Read();
						value = reader.ReadContentAsString();
						switch (e_ECUID)
						{
						case ConfigData.e_ECUID.A:
							liveViewSignalsA.Add(ConfigLiveView.GetLiveViewSignal_ByName(value, ConfigData.e_ECUID.A));
							break;
						case ConfigData.e_ECUID.B:
							liveViewSignalsB.Add(ConfigLiveView.GetLiveViewSignal_ByName(value, ConfigData.e_ECUID.B));
							break;
						}
						if (string.Compare(value, "Aux_signal") == 0)
						{
							int count = liveViewSignalsA.Count;
						}
						break;
					case "SIGNAL_DEFINITIONS":
						value = reader.NamespaceURI;
						if (value == "A")
						{
							e_ECUID = ConfigData.e_ECUID.A;
						}
						else if (value == "B")
						{
							e_ECUID = ConfigData.e_ECUID.B;
						}
						value = reader.Value;
						value = reader.Value;
						break;
					case "DAY":
						reader.Read();
						day = reader.ReadContentAsInt();
						break;
					case "MONTH":
						reader.Read();
						month = reader.ReadContentAsInt();
						break;
					case "YEAR":
						reader.Read();
						year = reader.ReadContentAsInt();
						break;
					case "HOUR":
						reader.Read();
						hour = reader.ReadContentAsInt();
						break;
					case "MINUTE":
						reader.Read();
						minute = reader.ReadContentAsInt();
						break;
					case "SECOND":
						reader.Read();
						second = reader.ReadContentAsInt();
						break;
					case "SW_ID":
						reader.Read();
						value = reader.Value;
						xmlData.recordStartTime = new DateTime(year, month, day, hour, minute, second);
						break;
					case "SW_VERSION_ECU":
						reader.Read();
						value = reader.Value;
						reader.ReadContentAsString();
						reader.ReadToFollowing("RECORDDATA");
						break;
					case "SW_INSTALLATION":
						reader.ReadToFollowing("RECORDDATA");
						break;
					case "RECORD_INTERVAL":
						value = reader.NamespaceURI;
						reader.Read();
						if (value == "A")
						{
							xmlData.recordIntervalA_ms = reader.ReadContentAsInt();
						}
						else if (value == "B")
						{
							xmlData.recordIntervalB_ms = reader.ReadContentAsInt();
						}
						break;
					}
				}
			}
			catch
			{
			}
		}

		public List<List<float>> ReadLiveViewSamples(XmlReader root, string ECU)
		{
			if (!(ECU == "A") && !(ECU == "B"))
			{
				throw new ArgumentException("Parameter ECU must be A or B");
			}
			List<List<float>> list = new List<List<float>>();
			if (!root.ReadToFollowing("SAMPLES"))
			{
				throw new Exception("no samples in file");
			}
			XmlReader xmlReader = root.ReadSubtree();
			if (!xmlReader.ReadToFollowing("SAMPLES"))
			{
				throw new Exception("no samples in file");
			}
			while (xmlReader.ReadToFollowing("SPL", ECU))
			{
				List<float> list2 = new List<float>();
				if (xmlReader.EOF)
				{
					break;
				}
				XmlReader xmlReader2 = xmlReader.ReadSubtree();
				if (!xmlReader2.ReadToFollowing("SPL", ECU))
				{
					break;
				}
				while (xmlReader2.ReadToFollowing("V", ECU))
				{
					xmlReader2.Read();
					float item = xmlReader2.ReadContentAsFloat();
					list2.Add(item);
				}
				list.Add(list2);
			}
			return list;
		}

		public int ReadLiveViewRecordInterval_ms(XmlReader root, string ECU)
		{
			if (!(ECU == "A") && !(ECU == "B"))
			{
				throw new ArgumentException("Parameter ECU must be A or B");
			}
			int num = 100;
			if (!root.ReadToFollowing("RECORD_INTERVAL", ECU))
			{
				throw new Exception("no record interval in file");
			}
			try
			{
				root.Read();
				return root.ReadContentAsInt();
			}
			catch
			{
				return 0;
			}
		}

		public List<LogSignalLiveView> ReadLiveViewSignalDefs(XmlReader root, string ECU)
		{
			ConfigData.e_ECUID ecuID = ConfigData.e_ECUID.A;
			if (ECU == "A")
			{
				ecuID = ConfigData.e_ECUID.A;
			}
			else if (ECU == "B")
			{
				ecuID = ConfigData.e_ECUID.B;
			}
			if (!(ECU == "A") && !(ECU == "B"))
			{
				throw new ArgumentException("Parameter ECU must be A or B");
			}
			List<LogSignalLiveView> list = new List<LogSignalLiveView>();
			if (!root.ReadToFollowing("SIGNAL_DEFINITIONS", ECU))
			{
				throw new Exception("no samples in file");
			}
			XmlReader xmlReader = root.ReadSubtree();
			if (!xmlReader.ReadToFollowing("SIGNAL_DEFINITIONS", ECU))
			{
				throw new Exception("no samples in file");
			}
			while (xmlReader.ReadToFollowing("SIGNAL_NAME", ECU) && !xmlReader.EOF)
			{
				xmlReader.Read();
				string name = xmlReader.ReadContentAsString();
				LogSignalLiveView liveViewSignal_ByName = ConfigLiveView.GetLiveViewSignal_ByName(name, ecuID);
				list.Add(liveViewSignal_ByName);
			}
			return list;
		}

		protected object ReadGenericValue(XmlReader reader, string name)
		{
			reader.ReadToFollowing(name);
			reader.Read();
			return reader.ReadContentAsObject();
		}

		protected object ReadGenericValue(XmlReader reader, string name, string nameSpace)
		{
			reader.ReadToFollowing(name, nameSpace);
			reader.Read();
			return reader.ReadContentAsObject();
		}
	}
}
